/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package database.entity;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author Stefan Martinov <stefan.maritnov@gmail.com>
 */
@Entity
@Table(name = "cart_item")
@NamedQueries({
    @NamedQuery(name = "CartItem.findAll", query = "SELECT c FROM CartItem c"),
    @NamedQuery(name = "CartItem.findByCartitemid", query = "SELECT c FROM CartItem c WHERE c.cartitemid = :cartitemid"),
    @NamedQuery(name = "CartItem.findByCartitemamount", query = "SELECT c FROM CartItem c WHERE c.cartitemamount = :cartitemamount")})
public class CartItem implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "CARTITEMID")
    private Integer cartitemid;
    @Basic(optional = false)
    @Column(name = "CARTITEMAMOUNT")
    private int cartitemamount;
    @JoinColumn(name = "CARTID", referencedColumnName = "CARTID")
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private ShoppingCart shoppingCart;
    @JoinColumn(name = "ITEMID", referencedColumnName = "ITEMID")
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private ShopItem shopItem;

    public CartItem() {
    }

    public CartItem(Integer cartitemid) {
        this.cartitemid = cartitemid;
    }

    public CartItem(Integer cartitemid, int cartitemamount) {
        this.cartitemid = cartitemid;
        this.cartitemamount = cartitemamount;
    }

    public Integer getCartitemid() {
        return cartitemid;
    }

    public void setCartitemid(Integer cartitemid) {
        this.cartitemid = cartitemid;
    }

    public int getCartitemamount() {
        return cartitemamount;
    }

    public void setCartitemamount(int cartitemamount) {
        this.cartitemamount = cartitemamount;
    }

    public ShoppingCart getShoppingCart() {
        return shoppingCart;
    }

    public void setShoppingCart(ShoppingCart shoppingCart) {
        this.shoppingCart = shoppingCart;
    }

    public ShopItem getShopItem() {
        return shopItem;
    }

    public void setShopItem(ShopItem shopItem) {
        this.shopItem = shopItem;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (cartitemid != null ? cartitemid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof CartItem)) {
            return false;
        }
        CartItem other = (CartItem) object;
        if ((this.cartitemid == null && other.cartitemid != null) || (this.cartitemid != null && !this.cartitemid.equals(other.cartitemid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "database.entity.CartItem[cartitemid=" + cartitemid + "]";
    }

}
